<?php
/**
 * Default Theme Manager Template
 *
 * @package OWL
 * @subpackage Default Template
 * @author KeiMOon
 * @since 1.0
 */
class Template_Themes_Manager extends Owl_Master_Template {
    protected function init() {
        $user = Owl_User::get_instance();
        if (!$user->is_logged_in()) {
            Owl_Functions::go_to_template("login");
        }
        assign("title", get_option("site_name") . " - " . __("Themes manager"));
        assign("page-title", __("Themes manager"));
        enqueue_style('default-setting,default-icon,default-theme-manager,default-ajax');
        enqueue_script('default-theme');

        $this->current_theme = Owl_Theme_Control::get_current_theme();
        $this->current_theme_setting = Owl_Theme_Control::load_setting(Owl_Theme_Control::get_current_theme());
        $this->all_settings = Owl_Theme_Control::load_all_setting();
    }

    protected function main_content() {
?>

<div id="setting-navigation">
    <?php Owl_Default_Content::setting_navigation(); ?>
    <div style="clear:both;"></div>
</div>
<div id="setting-page-header" class="has-icon icon-theme-manager-48">
    <div id="setting-page-title">
        <?php put("page-title"); ?>
    </div>
</div>
<div id="setting-main-content">
    <?php Owl_Default_Content::print_ajax_feedback(); ?>
    <div id="current-theme">
        <h3><?php echo __("Current theme"); ?></h3>
        <div class="setting-content inset">
            <table border="0" cellpadding="0" cellspacing="0">
                <tbody>
                    <tr>
                        <td class="theme-preview" width="200">
                            <?php echo Owl_Html::make_it_image(Owl_Theme_Control::get_theme_preview_url($this->current_theme_setting, Owl_Theme_Control::get_current_theme()), $this->current_theme_setting["theme_name"], 192); ?>
                        </td>
                        <td class="theme-info">
                            <?php
                                Owl_Theme_Control::print_theme_info(Owl_Theme_Control::get_current_theme());
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="theme-control" colspan="2">
                            <h4><?php echo __("Current theme customization"); ?></h4>
                            <?php if (Owl_Theme_Control::is_colorirable($this->current_theme) || (Owl_Theme_Control::is_customizable($this->current_theme))) { ?>
                                <?php if (get_option("site_effect")) : ?>
                                <div class="legend"><?php echo __("Hover to preview, click to change color scheme"); ?></div>
                                <?php else : ?>
                                <div class="legend"><?php echo __("Click to change color scheme"); ?></div>
                                <?php endif; ?>
                                <?php foreach((array)$this->current_theme_setting["color_schemes"] as $color_scheme) { ?>
                                    <?php if (get_option("current_body_class") == $color_scheme["scheme_class"]) { ?>
                                    <div class="color-scheme current">
                                    <?php } else { ?>
                                    <div class="color-scheme">
                                    <?php } ?>
                                        <a href="#" rel="<?php echo $color_scheme["scheme_class"] ?>" class="activate-color-scheme">
                                        <?php echo Owl_Html::make_it_image(Owl_Theme_Control::get_color_scheme_preview_url($color_scheme, Owl_Theme_Control::get_current_theme()), $color_scheme["scheme_name"], 192); ?>
                                        </a>
                                        <span class="color-scheme-title">
                                            <?php echo $color_scheme["scheme_name"]; ?>
                                        </span>
                                    </div>
                                <?php } ?>
                                <?php if (Owl_Theme_Control::is_customizable(Owl_Theme_Control::get_current_theme()) == 1) { ?>
                                    <?php if (get_option("current_body_class") == "custom") { ?>
                                    <div class="color-scheme current">
                                    <?php } else { ?>
                                    <div class="color-scheme">
                                    <?php } ?>
                                        <a href="<?php Owl_Link::template_url("theme-customize", true, array("var" => Owl_Theme_Control::get_current_theme())); ?>" rel="custom" class="activate-color-scheme">
                                        <?php echo Owl_Html::make_it_image(Owl_Link::image_url(false) . "default/theme-customize.jpg", __("Color customization"), 192); ?>
                                        </a>
                                        <span class="color-scheme-title">
                                        <?php echo __("Color customization"); ?>
                                        </span>
                                    </div>
                                <?php } elseif (Owl_Theme_Control::is_customizable(Owl_Theme_Control::get_current_theme()) == -1) { ?>
                                    <?php if (get_option("current_body_class") == "custom") { ?>
                                    <div class="color-scheme current">
                                    <?php } else { ?>
                                    <div class="color-scheme">
                                    <?php } ?>
                                        <?php echo Owl_Html::make_it_image(Owl_Link::image_url(false) . "default/theme-uncustomize.jpg", __("Color customization"), 192); ?>
                                        <span class="color-scheme-title">
                                        <?php echo __("Color customization"); ?>
                                        </span>
                                    </div>
                                <?php } ?>
                                <?php
                                    Owl_Form::print_hidden(array(
                                        "name" => "current_color_scheme",
                                        "value" => get_option("current_body_class")
                                    ));
                                ?>
                                <div style="clear:both;"></div>
                            <?php } 
                                else {
                                    echo __("There is no options for this theme");
                                }
                            ?>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div id="theme-list">
        <h3><?php echo __("Theme list"); ?></h3>
        <div class="legend"><?php echo __("Click the theme preview image to change theme"); ?></div>
        <div class="setting-content inset">
            <table border="0" cellpadding="0" cellspacing="0">
                <tbody>
                    <?php foreach((array)$this->all_settings as $theme => $theme_setting) { ?>
                    <?php if(Owl_Theme_Control::get_current_theme() != $theme) { ?>
                    <tr>
                        <td class="theme-preview" width="200">
                            <a href="#" class="change-theme" rel="<?php echo $theme ?>">
                            <?php echo Owl_Html::make_it_image(Owl_Theme_Control::get_theme_preview_url($theme_setting, $theme), $theme_setting["theme_name"], 192); ?>
                            </a>
                        </td>
                        <td class="theme-info">
                            <?php
                                Owl_Theme_Control::print_theme_info($theme);
                            ?>
                        </td>
                    </tr>
                    <?php } ?>
                    <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<?php
    }
}